

; Random event
; calls event at an average every time:th seconds


(load "physics-object.scm")
(load "optimization.scm")


(define random-event%
  (class physics-object%
    
    ; PUBLIC VARIABLES
    (init-field [time #i0]
                [event #f])
    ; PRIVATE VARIABLES
    (define time-since-trigger #i0)
    
    ; Update
    (define/override (update)
      (when event
        (set! time-since-trigger (fl+ time-since-trigger *time-delta*))
        (when (fl< time (fl* time-since-trigger (random)))
          (event)
          (set! time-since-trigger (- time-since-trigger time))))
      #t)
    
    ; Constructor/Initialization
    (super-new [affected-by-gravity #f] [interactive #f])))

